﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace HZ.Supervise.Web.Peculiar
{
    public partial class DelProcureCatalog : BasePage
    {
        string GID;
        public DelProcureCatalog()
        {
            this.ModuleNo = "特殊权限";
            this.PageOperateType = "维护";
        }
        HZ.Supervise.IBLL.IBLL_SpecialAuthority sp = HZ.Supervise.BLLFactory.IBLL_SpecialAuthority();
        protected void Page_Load(object sender, EventArgs e)
        {
            GID = Request["GID"];
            if (!IsPostBack)
            {
               
                dataBind();
            }
        }

        private void dataBind()
        {

            HZ.Supervise.IBLL.IBLL_ProcureCatalog ipro = HZ.Supervise.BLLFactory.IBLL_ProcureCatalog();
            Model.View.ProcureCatalog procureCatalog = ipro.GetProcureCatalogByID(GID);
            txtCompany_SC.Text = procureCatalog.CompanyName_SC;
            txtCompany_TB.Text = procureCatalog.CompanyName_TB;
            txtFactor.Text = procureCatalog.Factor.ToString();
            txtGoodsName.Text = procureCatalog.GoodsName;
            txtMedicineModelName.Text = procureCatalog.MedicineModelName;
            txtOutLook.Text = procureCatalog.Outlookc;
            txtSortSource.Text = HZ.Supervise.Web.Function.FormatDrugSource(procureCatalog.SortSource);
            txtProcurePrice.Text = procureCatalog.ProcurePrice.ToString();
            ViewState["price"] = procureCatalog.ProcurePrice.ToString();
            txtProductName.Text = procureCatalog.ProductName;
            txtSort.Text = procureCatalog.SortName;
            txtUnit.Text = procureCatalog.Unit;

        }


        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (this.HidAreaId.Value.Length<1)
            {
                this.Page.RegisterStartupScript("", "<script>alert('请选择需要撤废的区域!')</script>");
                return;
            }
            int count = 0;
            string areaId;
            if (this.cbkArea.Checked)
            {
                areaId = CurrentAccount.GetUser().Org.Area.AreaID;
            }
            else
            {
                areaId = this.HidAreaId.Value.Substring(0, HidAreaId.Value.Length - 1);
            }
            count = sp.InsertAreaDeleteProcure(areaId, GID, this.cbkArea.Checked, CurrentAccount.GetUser().UserID);
            if (count > 0)
            {
                this.Page.RegisterStartupScript("", "<script>alert('药品撤废成功!')</script>");
            }
            else if (count == -1)
            {
                this.Page.RegisterStartupScript("", "<script>alert('药品已撤废,不能重复添加!')</script>");
            }
            else
            {
                this.Page.RegisterStartupScript("", "<script>alert('药品撤废失败!请重新操作')</script>");
            }

        }

        protected void cbkArea_CheckedChanged(object sender, EventArgs e)
        {
            this.btnArea.Enabled = false;
        }
    }
}
